package com.example.redistest.controller;

import com.example.redistest.domain.tbUser;
import com.example.redistest.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/getUserById/{id}")
    public tbUser getUserById(@PathVariable("id") int id) {
        return userService.getUserById(id);
    }

    @RequestMapping("/addUser")
    public String addUser() {
        tbUser tbUser = new tbUser(31, "阿毛", "234", 1);
        userService.addUser(tbUser);
        return "ok";
    }

    @RequestMapping("/updateUser")
    public String updateUser() {
        tbUser tbUser = new tbUser(20, "阿刘", "456", 1);
        userService.updateUser(tbUser);
        return "ok";
    }

    @RequestMapping("/deleteUser/{id}")
    public String deleteUser(@PathVariable("id") int id) {
        userService.deleteUser(id);
        return "ok";
    }
}
